package com.ocom.company.controller;

import cn.hutool.core.bean.BeanUtil;
import com.ocom.common.constant.CompanyServiceUrl;
import com.ocom.common.entity.human.EntityPersonnelInfo;
import com.ocom.common.entity.master.EntityMngAccountInfo;
import com.ocom.common.request.company.MngAccountInfoRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.BeanCopyTool;
import com.ocom.common.utils.ResultUtil;
import com.ocom.company.service.MngAccountInfoService;
import com.ocom.company.vo.MngAccountInfoVo;
import java.util.ArrayList;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class MngAccountInfoController {

    @Autowired
    private MngAccountInfoService mngAccountInfoService;

    @PostMapping(CompanyServiceUrl.URL_account)
    public Result selectAccountsByPhone(@RequestBody MngAccountInfoRequest request) {
        List<EntityMngAccountInfo> list = mngAccountInfoService.selectAccountsByPhone(request);
        List<MngAccountInfoVo> mngAccountInfoVos = BeanCopyTool.convertCopyList(list,
          MngAccountInfoVo.class);
         List<MngAccountInfoVo> collect = mngAccountInfoVos.stream()
            .filter(mngAccountInfoVo -> {
                if (mngAccountInfoVo.getThirdType().equals("1")){
                    mngAccountInfoVo.setTypeName("手机号");
                    return true;
                }
                if (mngAccountInfoVo.getThirdType().equals("2")){
                    mngAccountInfoVo.setTypeName("微信");
                    return true;
                }
                if (mngAccountInfoVo.getThirdType().equals("3")){
                    mngAccountInfoVo.setTypeName("支付宝");
                    return true;
                }
                 mngAccountInfoVo.setTypeName("其它");
                return true;
                }
            ).collect(Collectors.toList());
        return ResultUtil.success(collect);
    }
    @PostMapping(CompanyServiceUrl.URL_addMngAccount)
    public Result addMngAccount(@RequestBody MngAccountInfoRequest mngAccountInfoRequest) throws Exception {
        return ResultUtil.success(mngAccountInfoService.addMngAccount(mngAccountInfoRequest));
    }

}
